package com.sghj.utils;



import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;

/**
 * @author xrx
 * @Date 2022/6/30
 * @apiNote
 */
public final class IDCardSM4Utils {

    /**
     * 秘钥
     */
    //public static String SM4_KEY = "2c81b51b30feffbd";

    public static byte[] ID_KEY ={0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0xde, (byte) 0xbc, (byte) 0x9a, 0x78, 0x56, 0x34, 0x12,0x57};

    public static final String ENCODING = "UTF-8";

    public static SM4 sm4 = SmUtil.sm4(ID_KEY);

    /**
     * 加密
     * @param Str
     * @return
     */
    public static String encrypt(String Str) {
       return sm4.encryptHex(Str, CharsetUtil.CHARSET_UTF_8);
    }

    /**
     * 解密
     * @param Str
     * @return
     */
    public static String decrypt(String Str) {
       return sm4.decryptStr(Str,CharsetUtil.CHARSET_UTF_8);
    }
}
